package com.lb.controller;

import com.baomidou.mybatisplus.annotation.TableField;
import com.lb.common.Result;
import com.lb.entity.DishCategory;
import com.lb.service.CategoryService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping
@CrossOrigin
@Slf4j
public class CategoryController {
     @Autowired
    private CategoryService categoryService;
     @GetMapping("/dish/kind")
    public Result getAllCategory(){
        List<DishCategory> list = categoryService.list();
            return Result.success(list);
    }
    @Transactional
    @GetMapping("/category/add")
    public Result addCategory(@RequestParam String categoryName){
         DishCategory dishCategory = new DishCategory();
         dishCategory.setCategoryName(categoryName);
         categoryService.save(dishCategory);
         return Result.success();
    }
    @GetMapping("/category/Byname")
    public Result findLikeCategoryName(@RequestParam String name){
        List<DishCategory> list= categoryService.selectByname(name);
        return Result.success(list);
    }
}
